require 'mu_api'
require 'erb'

# Run an existing template with some elements changed
# This script uses ruby templating with the ERB class

# The template should be a normal mu template
# marked up with templating tags:
#
# <%= Ruby expression -- replace with result %>

# For more information;
# http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html
# 
# Read original with templating tags. In this case, the template contains:
# <%= @mu_interface %>
# <%= @mu_ip %>
# <%= @target_ip %>
# <%= @default_gateway %>

# Set template values
@name = "Sample 1"
@mu_interface = "a1"
@mu_ip = "192.168.30.71"
@target_ip = "192.168.30.1"

# Read in template and apply new values
original = File.read("sample.xml")
sample = ERB.new(original)
template = sample.result

# Template now has new values that we can post and run
api = Mu_Api.new
api.post(template)
api.run

# Run against another host
@name = "Sample 2"
@target_ip = "192.168.30.3"
sample2 = ERB.new(original)
template2 = sample2.result
api.post(template2)
api.run


